package tdh.xt.entity.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import tdh.xt.enums.CustomResultCode;

@Getter
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ResultDto {
    private String msg;
    private Integer code;
    private Object data;

    public ResultDto(){}

    private ResultDto(String msg, Integer code, Object data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static ResultDto okOf(CustomResultCode result, Object data) {
        return new ResultDto(result.getMessage(), result.getCode(), data);
    }

    public static ResultDto errorOf(CustomResultCode result) {
        return okOf(result, null);
    }
    public static ResultDto errorOf(CustomResultCode result, Object data) {
        return okOf(result, data);
    }
    public static ResultDto okOf(CustomResultCode result) {
        return okOf(result, null);
    }
}
